package cn.green.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author wang.yishu
 * @version 1.0
 * @className OrmAppUtils
 * @date 2025/5/22 16:09
 */
public class OrmAppUtils implements ApplicationContextAware {
    /**
     * 上下文对象实例
     */
    private static ApplicationContext applicationContext;


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        OrmAppUtils.applicationContext = applicationContext;
    }

    /**
     * 通过class获取Bean.
     */
    public static <T> T getBean(Class<T> clazz) {
        return OrmAppUtils.applicationContext.getBean(clazz);
    }
}
